home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / SIZING.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-29  |  5.7 KB  |  205 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    Sizing fixing and positioning routine                            *
  4.  *                                                                    *
  5.  *    Copyright (C) 1993 - 1994, BitGate Software and Clever Bits.    *
  6.  *    All Rights Reserved.                                            *
  7.  *                                                                    *
  8.  *    The revolutionary sizing fix that was desperately needed with    *
  9.  *    WinLIB PRO.  These routines fix the position of 3D objects (as    *
  10.  *    a result of object fixing, it's a GEM bug), and they also fix    *
  11.  *    object sizes for higher resolutions (one file, many resolutions)*
  12.  *                                                                    *
  13.  ********************************************************************
  14.  *                                                                    *
  15.  *    Update log:                                                        *
  16.  *                                                                    *
  17.  *    [15.12.93 - 29.3.94] Ken Hollis                                    *
  18.  *        position_fix    - added for position fixing of root objects    *
  19.  *                        - worked on sizing routine                    *
  20.  *                        - tried out Markus Gutschke's sizing routs    *
  21.  *                        - fixed for children with 3D parents        *
  22.  *                        - added additional fix for 3D menu bars        *
  23.  *                        - fixed MENULINE type for 3D menu bars        *
  24.  *                        - added fix for TITLES and their siblings    *
  25.  *                        - fixed 3D boxes from TITLES...  Weird...    *
  26.  *                        - made safer and secure for non-3D menus    *
  27.  *                        - added thickness check for fixes           *
  28.  *                        - added fix for any unfixed objects            *
  29.  *                                                                    *
  30.  ********************************************************************/
  31.  
  32. #include "winlib.h"
  33.  
  34. #ifndef __SIZING__
  35. #define __SIZING__
  36. #endif
  37.  
  38. /*
  39.  *    Fix rooted object coordinates
  40.  *
  41.  *    Since we had a sizing problem, the main problem was with the
  42.  *    objects that had multiple roots; these objects had to be moved
  43.  *    down one and to the right one since they were modified.  If you
  44.  *    have more than one root without this fix, things get hectic, as
  45.  *    you might imagine.  It's just a simple problem that was easily
  46.  *    fixed, thanks to Markus Gutschke's help...
  47.  */
  48. GLOBAL void position_fix(OBJECT *obj)
  49. {
  50.     int object = 1, objc, parent;
  51.     int i, j, x, y, w, h, x1, y1;
  52.     BOOL menu = FALSE;
  53.  
  54.     do {
  55.         if (obj[object++].ob_type == G_TITLE)
  56.             menu = TRUE;
  57.     } while(!(obj[object].ob_flags & LASTOB));
  58.  
  59.     object = 1;
  60.  
  61.     if (!menu) {
  62.         do {
  63.             object++;
  64.             parent = object;
  65.             if ((obj[parent].ob_state & DRAW3D) && !(obj[parent].ob_state & ALREADYMOD)) {
  66.                 for (objc = obj[parent].ob_head; objc>=0 && objc!=parent; objc = obj[objc].ob_next) {
  67.                     if ((obj[parent].ob_state & DRAW3D) && (objc!=1)) {
  68.                         if (!(obj[objc].ob_state & ALREADYMOD)) {
  69.                             EXTINFO *ex = obj[parent].ob_spec.userblk->ub_parm;
  70.  
  71.                             if (ex->te_thickness < 0) {
  72.                                 obj[objc].ob_x += (abs(ex->te_thickness));
  73.                                 obj[objc].ob_y += (abs(ex->te_thickness));
  74.                                 obj[objc].ob_state |= ALREADYMOD;
  75.                             }
  76.                         }
  77.                     }
  78.                 }
  79.  
  80.                 while(parent >= 0) {
  81.                     objc = parent;
  82.                     parent = -1;
  83.  
  84.                     i = objc;
  85.  
  86.                     do {
  87.                         if ((obj[parent].ob_state & DRAW3D) && (i!=1)) {
  88.                             EXTINFO *ex = obj[parent].ob_spec.userblk->ub_parm;
  89.  
  90.                             if (!(obj[i].ob_state & ALREADYMOD)) {
  91.                                 if (ex->te_thickness < 0) {
  92.                                     obj[i].ob_x += (abs(ex->te_thickness));
  93.                                     obj[i].ob_y += (abs(ex->te_thickness));
  94.                                     obj[i].ob_state |= ALREADYMOD;
  95.                                 }
  96.                             }
  97.                         }
  98.  
  99.                         if ((j = obj[i].ob_next) >= 0 && obj[j].ob_tail == i) {
  100.                             parent = j;
  101.                             i = obj[j].ob_head;
  102.                         } else
  103.                             i = j;
  104.                     } while(i>=0 && i!=objc);
  105.                 }
  106.             }
  107.         } while(!(obj[object].ob_flags & LASTOB));
  108.     }
  109.  
  110.     if ((obj[object].ob_flags & LASTOB) &&
  111.         !(obj[object].ob_state & ALREADYMOD) &&
  112.         (obj[object].ob_state & DRAW3D) &&
  113.         !(menu)){
  114.         obj[object].ob_x++;
  115.         obj[object].ob_y++;
  116.     }
  117.  
  118.     object = 2;
  119.  
  120.     if ((menu) && (obj[1].ob_state & DRAW3D)) {
  121.         obj[0].ob_state |= ALREADYMOD;    /* Desktop size */
  122.         obj[1].ob_state |= ALREADYMOD;    /* Menu bar drawing line */
  123.         obj[2].ob_state |= ALREADYMOD;    /* Object holding titles */
  124.  
  125.         do {
  126.             object++;
  127.             parent = object;
  128.              if (!(obj[parent].ob_state & ALREADYMOD)) {
  129.                 for (objc = obj[parent].ob_head; objc>=0 && objc!=parent; objc = obj[objc].ob_next) {
  130.                     if (objc!=1) {
  131.                         if (!(obj[objc].ob_state & ALREADYMOD) && (obj[parent].ob_type != G_TITLE)) {
  132.                             obj[objc].ob_x++;
  133.                             obj[objc].ob_y++;
  134.                             obj[objc].ob_state |= ALREADYMOD;
  135.                         }
  136.                     }
  137.                 }
  138.  
  139.                 while(parent >= 0) {
  140.                     objc = parent;
  141.                     parent = -1;
  142.  
  143.                     i = objc;
  144.  
  145.                     do {
  146.                         if ((obj[parent].ob_type != G_TITLE) && (i!=1)) {
  147.                             if (!(obj[i].ob_state & ALREADYMOD)) {
  148.                                 obj[i].ob_x++;
  149.                                 obj[i].ob_y++;
  150.                                 obj[i].ob_state |= ALREADYMOD;
  151.                             }
  152.                         }
  153.  
  154.                         if ((j = obj[i].ob_next) >= 0 && obj[j].ob_tail == i) {
  155.                             parent = j;
  156.                             i = obj[j].ob_head;
  157.                         } else
  158.                             i = j;
  159.                     } while(i>=0 && i!=objc);
  160.                 }
  161.             }
  162.         } while (!(obj[object].ob_flags & LASTOB));
  163.     }
  164.  
  165.     object = 2;
  166.     while (!(obj[object].ob_flags & LASTOB)) {
  167.         if ((!(obj[object].ob_state & ALREADYMOD)) &&
  168.             (obj[object].ob_state & DRAW3D)) {
  169.             obj[object].ob_x++;
  170.             obj[object].ob_y++;
  171.             obj[object].ob_state |= ALREADYMOD;
  172.         }
  173.  
  174.         object++;
  175.     }
  176.  
  177.     object = 0;
  178.     while (!(obj[object].ob_flags & LASTOB)) {
  179.         if (obj[object].ob_state & ALREADYMOD)
  180.             obj[object].ob_state &= ~ALREADYMOD;
  181.         if (menu && (obj[object].ob_type == G_TITLE) && (obj[1].ob_state & DRAW3D)) {
  182.             obj[object].ob_x--;
  183.             obj[object].ob_y--;
  184.         }
  185.         object++;
  186.     }
  187.  
  188.     object = 3;
  189.  
  190.     while (!(obj[object].ob_flags & LASTOB)) {
  191.         if (menu) {
  192.             if (obj[object].ob_state & DRAW3D) {
  193.                 EXTINFO *ex = (EXTINFO *) obj[object].ob_spec.userblk->ub_parm;
  194.  
  195.                 if ((ex->oldtype == G_BOX) ||
  196.                     (ex->oldtype == G_IBOX)) {
  197.                     obj[object].ob_x -= 2;
  198.                     obj[object].ob_y -= 2;
  199.                 }
  200.             }
  201.         }
  202.  
  203.         object++;
  204.     }
  205. }